// pages/eat/eat.js
var config = require("../../utils/config.js");
var network = require("../../utils/network.js");
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    cleaning: '',  //设计师匹配
    list: ''  //下面文本
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
    this.getCleaning();
  },

  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
      })
    }
  },
  getData: function () {
    network.request({
      url: config.host + 'api_features/features',
      method: "POST",
      data: { pid: 1 },
      success: res => {
        console.log("饮食运动计划")
        console.log(res.data.data)
        if (res.data.code == 99) {
          this.setData({
            eatData: res.data.data
          })
          let listRes = res.data.data.items; //要解析的数据
          for (let i = 0; i < listRes.length; i++) {
            WxParse.wxParse('topic' + i, 'html', listRes[i].content, this);
            if (i === listRes.length - 1) {
              WxParse.wxParseTemArray("listArr", 'topic', listRes.length, this)
            }
          }
          console.log(this.data.listArr)
        } else {
          wx.showToast({
            title: res.data.code,
            icon: "none"
          })
        }
      }
    })
  },
  getCleaning: function () {
    wx.request({
      url: config.host + 'api_cleaner/randDesign',
      method: "POST",
      success: res => {
        if (res.data.code == 99) {
          this.setData({
            cleaning: res.data.data
          })
        }
      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})